<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>SmilesDrawer.js - Documentation</title>

    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module.exports.html">exports</a></li></ul><h3>Global</h3><ul><li><a href="global.html#_bridgeDfs">_bridgeDfs</a></li><li><a href="global.html#_ccCountDfs">_ccCountDfs</a></li><li><a href="global.html#_ccGetDfs">_ccGetDfs</a></li><li><a href="global.html#_init">_init</a></li><li><a href="global.html#_initInfos">_initInfos</a></li><li><a href="global.html#add">add</a></li><li><a href="global.html#addAnchoredRing">addAnchoredRing</a></li><li><a href="global.html#addChild">addChild</a></li><li><a href="global.html#addEdge">addEdge</a></li><li><a href="global.html#addNeighbouringElement">addNeighbouringElement</a></li><li><a href="global.html#addRing">addRing</a></li><li><a href="global.html#addRingConnection">addRingConnection</a></li><li><a href="global.html#addVertex">addVertex</a></li><li><a href="global.html#angle">angle</a></li><li><a href="global.html#apothem">apothem</a></li><li><a href="global.html#areSetsEqual">areSetsEqual</a></li><li><a href="global.html#areVerticesInSameRing">areVerticesInSameRing</a></li><li><a href="global.html#atomicNumbers">atomicNumbers</a></li><li><a href="global.html#attachPseudoElement">attachPseudoElement</a></li><li><a href="global.html#averageDirection">averageDirection</a></li><li><a href="global.html#backupRingInformation">backupRingInformation</a></li><li><a href="global.html#backupRings">backupRings</a></li><li><a href="global.html#bonds">bonds</a></li><li><a href="global.html#bondsToAtoms">bondsToAtoms</a></li><li><a href="global.html#centralAngle">centralAngle</a></li><li><a href="global.html#chooseSide">chooseSide</a></li><li><a href="global.html#clear">clear</a></li><li><a href="global.html#clockwise">clockwise</a></li><li><a href="global.html#clone">clone</a></li><li><a href="global.html#contains">contains</a></li><li><a href="global.html#containsAll">containsAll</a></li><li><a href="global.html#containsRing">containsRing</a></li><li><a href="global.html#count">count</a></li><li><a href="global.html#createBridgedRing">createBridgedRing</a></li><li><a href="global.html#createNextBond">createNextBond</a></li><li><a href="global.html#createRing">createRing</a></li><li><a href="global.html#deepCopy">deepCopy</a></li><li><a href="global.html#degFactor">degFactor</a></li><li><a href="global.html#distance">distance</a></li><li><a href="global.html#distanceSq">distanceSq</a></li><li><a href="global.html#divide">divide</a></li><li><a href="global.html#divideScalar">divideScalar</a></li><li><a href="global.html#dot">dot</a></li><li><a href="global.html#draw">draw</a></li><li><a href="global.html#drawAromaticityRing">drawAromaticityRing</a></li><li><a href="global.html#drawBall">drawBall</a></li><li><a href="global.html#drawCircle">drawCircle</a></li><li><a href="global.html#drawDashedWedge">drawDashedWedge</a></li><li><a href="global.html#drawDebugPoint">drawDebugPoint</a></li><li><a href="global.html#drawDebugText">drawDebugText</a></li><li><a href="global.html#drawEdge">drawEdge</a></li><li><a href="global.html#drawEdges">drawEdges</a></li><li><a href="global.html#drawLine">drawLine</a></li><li><a href="global.html#drawPoint">drawPoint</a></li><li><a href="global.html#drawText">drawText</a></li><li><a href="global.html#drawVertices">drawVertices</a></li><li><a href="global.html#drawWedge">drawWedge</a></li><li><a href="global.html#each">each</a></li><li><a href="global.html#eachMember">eachMember</a></li><li><a href="global.html#edgeRingCount">edgeRingCount</a></li><li><a href="global.html#equals">equals</a></li><li><a href="global.html#extend">extend</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#getAdjacencyList">getAdjacencyList</a></li><li><a href="global.html#getAdjacencyMatrix">getAdjacencyMatrix</a></li><li><a href="global.html#getAngle">getAngle</a></li><li><a href="global.html#getAtomicNumber">getAtomicNumber</a></li><li><a href="global.html#getAttachedPseudoElements">getAttachedPseudoElements</a></li><li><a href="global.html#getAttachedPseudoElementsCount">getAttachedPseudoElementsCount</a></li><li><a href="global.html#getBondCount">getBondCount</a></li><li><a href="global.html#getBridgedRingRings">getBridgedRingRings</a></li><li><a href="global.html#getBridgedRings">getBridgedRings</a></li><li><a href="global.html#getBridges">getBridges</a></li><li><a href="global.html#getClosestVertex">getClosestVertex</a></li><li><a href="global.html#getColor">getColor</a></li><li><a href="global.html#getCommonRingbondNeighbour">getCommonRingbondNeighbour</a></li><li><a href="global.html#getCommonRings">getCommonRings</a></li><li><a href="global.html#getComponentsAdjacencyMatrix">getComponentsAdjacencyMatrix</a></li><li><a href="global.html#getConnectedComponentCount">getConnectedComponentCount</a></li><li><a href="global.html#getConnectedComponents">getConnectedComponents</a></li><li><a href="global.html#getCurrentCenterOfMass">getCurrentCenterOfMass</a></li><li><a href="global.html#getCurrentCenterOfMassInNeigbourhood">getCurrentCenterOfMassInNeigbourhood</a></li><li><a href="global.html#getDistanceMatrix">getDistanceMatrix</a></li><li><a href="global.html#getDoubleBondCount">getDoubleBondCount</a></li><li><a href="global.html#getDrawnNeighbours">getDrawnNeighbours</a></li><li><a href="global.html#getDuplicateAtomicNumbers">getDuplicateAtomicNumbers</a></li><li><a href="global.html#getEdge">getEdge</a></li><li><a href="global.html#getEdgeCount">getEdgeCount</a></li><li><a href="global.html#getEdgeList">getEdgeList</a></li><li><a href="global.html#getEdgeNormals">getEdgeNormals</a></li><li><a href="global.html#getEdges">getEdges</a></li><li><a href="global.html#getFusedRings">getFusedRings</a></li><li><a href="global.html#getHeavyAtomCount">getHeavyAtomCount</a></li><li><a href="global.html#getLargestOrAromaticCommonRing">getLargestOrAromaticCommonRing</a></li><li><a href="global.html#getLeftChiral">getLeftChiral</a></li><li><a href="global.html#getLeftElement">getLeftElement</a></li><li><a href="global.html#getLeftVector">getLeftVector</a></li><li><a href="global.html#getLength">getLength</a></li><li><a href="global.html#getNeighbourCount">getNeighbourCount</a></li><li><a href="global.html#getNeighbours">getNeighbours</a></li><li><a href="global.html#getNextInRing">getNextInRing</a></li><li><a href="global.html#getNonRingNeighbours">getNonRingNeighbours</a></li><li><a href="global.html#getOrder">getOrder</a></li><li><a href="global.html#getOrderedNeighbours">getOrderedNeighbours</a></li><li><a href="global.html#getOverlapScore">getOverlapScore</a></li><li><a href="global.html#getPathIncludedDistanceMatrices">getPathIncludedDistanceMatrices</a></li><li><a href="global.html#getPolygon">getPolygon</a></li><li><a href="global.html#getRightChiral">getRightChiral</a></li><li><a href="global.html#getRightElement">getRightElement</a></li><li><a href="global.html#getRightVector">getRightVector</a></li><li><a href="global.html#getRing">getRing</a></li><li><a href="global.html#getRingbondCount">getRingbondCount</a></li><li><a href="global.html#getRingbondType">getRingbondType</a></li><li><a href="global.html#getRingCandidates">getRingCandidates</a></li><li><a href="global.html#getRingConnection">getRingConnection</a></li><li><a href="global.html#getRingConnections">getRingConnections</a></li><li><a href="global.html#getRingCount">getRingCount</a></li><li><a href="global.html#getRings">getRings</a></li><li><a href="global.html#getRotateAwayFromAngle">getRotateAwayFromAngle</a></li><li><a href="global.html#getRotateToAngle">getRotateToAngle</a></li><li><a href="global.html#getRotateTowardsAngle">getRotateTowardsAngle</a></li><li><a href="global.html#getSize">getSize</a></li><li><a href="global.html#getSpanningTreeNeighbours">getSpanningTreeNeighbours</a></li><li><a href="global.html#getSpiros">getSpiros</a></li><li><a href="global.html#getSSSR">getSSSR</a></li><li><a href="global.html#getSubgraphAdjacencyList">getSubgraphAdjacencyList</a></li><li><a href="global.html#getSubgraphAdjacencyMatrix">getSubgraphAdjacencyMatrix</a></li><li><a href="global.html#getSubgraphDistanceMatrix">getSubgraphDistanceMatrix</a></li><li><a href="global.html#getSubringCenter">getSubringCenter</a></li><li><a href="global.html#getSubtreeOverlapScore">getSubtreeOverlapScore</a></li><li><a href="global.html#getTextDirection">getTextDirection</a></li><li><a href="global.html#getTotalOverlapScore">getTotalOverlapScore</a></li><li><a href="global.html#getTreeDepth">getTreeDepth</a></li><li><a href="global.html#getVertexList">getVertexList</a></li><li><a href="global.html#getVertices">getVertices</a></li><li><a href="global.html#getVerticesAt">getVerticesAt</a></li><li><a href="global.html#hasBridgedRing">hasBridgedRing</a></li><li><a href="global.html#hasDuplicateAtomicNumbers">hasDuplicateAtomicNumbers</a></li><li><a href="global.html#hasEdge">hasEdge</a></li><li><a href="global.html#haveCommonRingbond">haveCommonRingbond</a></li><li><a href="global.html#initPseudoElements">initPseudoElements</a></li><li><a href="global.html#initRings">initRings</a></li><li><a href="global.html#innerAngle">innerAngle</a></li><li><a href="global.html#intersection">intersection</a></li><li><a href="global.html#invert">invert</a></li><li><a href="global.html#isBenzeneLike">isBenzeneLike</a></li><li><a href="global.html#isBridge">isBridge</a></li><li><a href="global.html#isEdgeInRing">isEdgeInRing</a></li><li><a href="global.html#isEdgeRotatable">isEdgeRotatable</a></li><li><a href="global.html#isInPolygon">isInPolygon</a></li><li><a href="global.html#isPartOfBridgedRing">isPartOfBridgedRing</a></li><li><a href="global.html#isPointInRing">isPointInRing</a></li><li><a href="global.html#isRingAromatic">isRingAromatic</a></li><li><a href="global.html#isSupersetOf">isSupersetOf</a></li><li><a href="global.html#isTerminal">isTerminal</a></li><li><a href="global.html#kkLayout">kkLayout</a></li><li><a href="global.html#length">length</a></li><li><a href="global.html#lengthSq">lengthSq</a></li><li><a href="global.html#mass">mass</a></li><li><a href="global.html#matrixToString">matrixToString</a></li><li><a href="global.html#maxBonds">maxBonds</a></li><li><a href="global.html#meanAngle">meanAngle</a></li><li><a href="global.html#merge">merge</a></li><li><a href="global.html#midpoint">midpoint</a></li><li><a href="global.html#multiply">multiply</a></li><li><a href="global.html#multiplyScalar">multiplyScalar</a></li><li><a href="global.html#neighbouringElementsEqual">neighbouringElementsEqual</a></li><li><a href="global.html#normalize">normalize</a></li><li><a href="global.html#normalized">normalized</a></li><li><a href="global.html#normals">normals</a></li><li><a href="global.html#parityOfPermutation">parityOfPermutation</a></li><li><a href="global.html#pathSetsContain">pathSetsContain</a></li><li><a href="global.html#polyCircumradius">polyCircumradius</a></li><li><a href="global.html#position">position</a></li><li><a href="global.html#print">print</a></li><li><a href="global.html#printRingInfo">printRingInfo</a></li><li><a href="global.html#radFactor">radFactor</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#removeAll">removeAll</a></li><li><a href="global.html#removeRing">removeRing</a></li><li><a href="global.html#removeRingConnection">removeRingConnection</a></li><li><a href="global.html#removeRingConnectionsBetween">removeRingConnectionsBetween</a></li><li><a href="global.html#removeUnique">removeUnique</a></li><li><a href="global.html#reset">reset</a></li><li><a href="global.html#resolvePrimaryOverlaps">resolvePrimaryOverlaps</a></li><li><a href="global.html#resolveSecondaryOverlaps">resolveSecondaryOverlaps</a></li><li><a href="global.html#restoreRingInformation">restoreRingInformation</a></li><li><a href="global.html#restoreRings">restoreRings</a></li><li><a href="global.html#rotate">rotate</a></li><li><a href="global.html#rotateAround">rotateAround</a></li><li><a href="global.html#rotateAwayFrom">rotateAwayFrom</a></li><li><a href="global.html#rotateSubtree">rotateSubtree</a></li><li><a href="global.html#rotateTo">rotateTo</a></li><li><a href="global.html#rotateToXAxis">rotateToXAxis</a></li><li><a href="global.html#round">round</a></li><li><a href="global.html#sameSideAs">sameSideAs</a></li><li><a href="global.html#scalarProjection">scalarProjection</a></li><li><a href="global.html#scale">scale</a></li><li><a href="global.html#setLeftVector">setLeftVector</a></li><li><a href="global.html#setOrder">setOrder</a></li><li><a href="global.html#setParentVertexId">setParentVertexId</a></li><li><a href="global.html#setPosition">setPosition</a></li><li><a href="global.html#setPositionFromVector">setPositionFromVector</a></li><li><a href="global.html#setRightVector">setRightVector</a></li><li><a href="global.html#setRingCenter">setRingCenter</a></li><li><a href="global.html#setTheme">setTheme</a></li><li><a href="global.html#shorten">shorten</a></li><li><a href="global.html#shortenFrom">shortenFrom</a></li><li><a href="global.html#shortenLeft">shortenLeft</a></li><li><a href="global.html#shortenRight">shortenRight</a></li><li><a href="global.html#shortenTo">shortenTo</a></li><li><a href="global.html#SmilesDrawer">SmilesDrawer</a></li><li><a href="global.html#sortByAtomicNumber">sortByAtomicNumber</a></li><li><a href="global.html#sortByAtomicNumberDesc">sortByAtomicNumberDesc</a></li><li><a href="global.html#subtract">subtract</a></li><li><a href="global.html#threePointangle">threePointangle</a></li><li><a href="global.html#toDeg">toDeg</a></li><li><a href="global.html#toggle">toggle</a></li><li><a href="global.html#toRad">toRad</a></li><li><a href="global.html#toString">toString</a></li><li><a href="global.html#traverseBF">traverseBF</a></li><li><a href="global.html#traverseTree">traverseTree</a></li><li><a href="global.html#twoPI">twoPI</a></li><li><a href="global.html#unique">unique</a></li><li><a href="global.html#units">units</a></li><li><a href="global.html#updateOther">updateOther</a></li><li><a href="global.html#updateSize">updateSize</a></li><li><a href="global.html#whichSide">whichSide</a></li></ul>
</nav>

<div id="main">
    
    <h1 class="page-title">SmilesDrawer.js</h1>
    

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>//@ts-check
import Drawer from './Drawer'

/**
 * The SmilesDrawer namespace.
 * @typicalname SmilesDrawer
 */
let SmilesDrawer = {
    Version: '1.0.0'
};

/**
 * Cleans a SMILES string (removes non-valid characters)
 *
 * @static
 * @param {String} smiles A SMILES string.
 * @returns {String} The clean SMILES string.
 */
SmilesDrawer.clean = function(smiles) {
    return smiles.replace(/[^A-Za-z0-9@\.\+\-\?!\(\)\[\]\{\}/\\=#\$:\*]/g,'');
}

/**
 * Applies the smiles drawer draw function to each canvas element that has a smiles string in the data-smiles attribute.
 *
 * @static
 * @param {Object} options SmilesDrawer options.
 * @param {String} [selector='canvas[data-smiles]'] Selectors for the draw areas (canvas elements).
 * @param {String} [themeName='light'] The theme to apply.
 * @param {Function} [onError='null'] A callback function providing an error object.
 */
SmilesDrawer.apply = function(options, selector='canvas[data-smiles]', themeName='light', onError=null) {
    let smilesDrawer = new Drawer(options);
    let elements = document.querySelectorAll(selector);

    for (var i = 0; i &lt; elements.length; i++) {
        let element = elements[i];

        SmilesDrawer.parse(element.getAttribute('data-smiles'), function(tree) {
            smilesDrawer.draw(tree, element, themeName, false);
        }, function(err) {
          if (onError) {
            onError(err);
          }
        });
    }
}

/**
 * Parses the entered smiles string.
 * 
 * @static
 * @param {String} smiles A SMILES string.
 * @param {Function} successCallback A callback that is called on success with the parse tree.
 * @param {Function} errorCallback A callback that is called with the error object on error.
 */
SmilesDrawer.parse = function(smiles, successCallback, errorCallback) {
    try {
        if (successCallback) {
            successCallback(SmilesDrawer.Parser.parse(smiles));
        }
    } catch (err) {
        if (errorCallback) {
            errorCallback(err);
        }
    }
}


// There be dragons (polyfills)

if (!Array.prototype.fill) {
  Object.defineProperty(Array.prototype, 'fill', {
    value: function(value) {

      // Steps 1-2.
      if (this == null) {
        throw new TypeError('this is null or not defined');
      }

      var O = Object(this);

      // Steps 3-5.
      var len = O.length >>> 0;

      // Steps 6-7.
      var start = arguments[1];
      var relativeStart = start >> 0;

      // Step 8.
      var k = relativeStart &lt; 0 ?
        Math.max(len + relativeStart, 0) :
        Math.min(relativeStart, len);

      // Steps 9-10.
      var end = arguments[2];
      var relativeEnd = end === undefined ?
        len : end >> 0;

      // Step 11.
      var final = relativeEnd &lt; 0 ?
        Math.max(len + relativeEnd, 0) :
        Math.min(relativeEnd, len);

      // Step 12.
      while (k &lt; final) {
        O[k] = value;
        k++;
      }

      // Step 13.
      return O;
    }
  });
}</code></pre>
        </article>
    </section>




</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 12:43:33 GMT+0100 (CET) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>
